package cn.muqingfeng.api;

import java.util.HashMap;
import java.util.Map;

import android.content.Context;
import cn.muqingfeng.api.to.UserTO;
import cn.muqingfeng.util.AccountManager;

public class ApiContext {
	private static ApiContext mInstance;
	private Context mContext;

	public ApiContext(Context context) {
		this.mContext = context;
	}

	public synchronized static ApiContext create(Context context) {
		return mInstance == null ? mInstance = new ApiContext(context) : mInstance;
	}

	public Map<String, String> getHeaders(boolean needLogin) {
		HashMap<String, String> headers = new HashMap<String, String>();
		if (needLogin) {
			UserTO user = AccountManager.getUser(mContext);
			if (user != null) {
				headers.put(UriHelper.PARAMS_HEADER_USERNAME, user.getUsername());
				headers.put(UriHelper.PARAMS_HEADER_PASSWORD, AccountManager.getPassword(mContext));
			}
		}
		return headers;
	}

}
